package guoanmaker.operator.business.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.operator.business.model.BackgroundPicture;
import guoanmaker.operator.business.model.InRoundPhone;

import guoanmaker.operator.business.model.OperatorHotBusiness;
import guoanmaker.operator.business.service.OperatorHotBusinessServiceInterface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(ApiController.OPERATOR_HOT_BUSINESS)
public class OperatorHotBusinessController {
	@Autowired
	private OperatorHotBusinessServiceInterface operatorHotBusinessServiceInterface;
	 @ApiOperation(value = "保存热门服务商", notes = "新增/修改热门服务商")
	    @PostMapping(value = "saveOperatorHotBusiness")
	    public AjaxJson saveHeadline(@RequestBody InRoundPhone inRoundPhone) {
		 AjaxJson ajaxJson=new AjaxJson();
	    	try{
	    		OperatorHotBusiness[] appheads=inRoundPhone.getOperatorHotBusinesses();
	    		operatorHotBusinessServiceInterface.delectAllBycitycode(inRoundPhone.getCityId());
		    	for(OperatorHotBusiness apphead:appheads){
		    		/*if(apphead.getId()!=null&&!apphead.getId().equals("")){
		    		operatorHeadlineServiceInterface.deleteHeadlineById(apphead.getId());}*/
		    		apphead.setCreateDate(new Date());
		    		apphead.setCityId(inRoundPhone.getCityId());
		    		
		    		operatorHotBusinessServiceInterface.saveOperatorHotBusiness(apphead);
		    	}
		    	ajaxJson.setSuccess(true).setStatus(200).setData(null);
	    	}catch(Exception e){
	    		e.printStackTrace();
	    		ajaxJson.setSuccess(true).setStatus(250).setData(null);
	    	}
	        return ajaxJson;
	    }

	 
	 @ApiOperation(value = "查询所有热门服务商", notes = "查询所有所有热门服务商")
	    @PostMapping(value = "getAllOperatorHotBusiness")
	    public AjaxJson getAllOperatorHotBusiness(String cityId) {
		 AjaxJson ajaxJson=new AjaxJson();
	    	try{
	    	List<OperatorHotBusiness> ops=operatorHotBusinessServiceInterface.getAllOperatorHotBusinesse(cityId);
	    	
	        	ajaxJson.setSuccess(true).setStatus(200).setData(ops);
	        
	    	}catch(Exception e){
	    		e.printStackTrace();
	    		 ajaxJson.setSuccess(false).setStatus(250).setData(null);
	    	}
	    	return ajaxJson;
	    }
	 
	 
	 @ApiOperation(value = "验证热门服务商", notes = "验证热门服务商")
	    @PostMapping(value = "valideOperatorHotBusiness")
	    public AjaxJson valideOperatorHotBusiness(String busNumber) {
		 AjaxJson ajaxJson=new AjaxJson();
	    	try{
	    	Map remap=operatorHotBusinessServiceInterface.selectProvideBusinessValia(busNumber);
	    	
	        	ajaxJson.setSuccess(true).setStatus(200).setData(remap).setMsg(null);
	        
	    	}catch(Exception e){
	    		e.printStackTrace();
	    		 ajaxJson.setSuccess(false).setStatus(250).setData(null).setMsg(null);
	    	}
	    	return ajaxJson;
	    }
	 
	 @ApiOperation(value = "查询服务商", notes = "查询服务商")
	 @PostMapping("selectOperatorHotBusiness")
	 public AjaxJson selectOperatorHotBusiness(String busNumber) {
		 AjaxJson ajaxJson=new AjaxJson();
		 try {
			 ajaxJson.setSuccess(true).setStatus(200).setData(operatorHotBusinessServiceInterface.selectOperatorHotBusiness(busNumber)).setMsg("操作成功");
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setData(null).setMsg("操作失败");
		}
		 return ajaxJson;
	 }
}
